(function () {
  var $ajax = function (url, success, error) {
    this.url = url;
    this.data = {};
    this.dataType = "application/json";
    this.async = false;
    this.success = success;
    this.error = error;
  };

  $ajax.prototype = {
    postStart: function () {
      var me = this;

      $.ajax({
        type: 'post',
        url: this.url,
        contentType: this.dataType,
        async: this.async,
        data: this.data,
        beforeSend: function (data) {

        },
        success: function (data) {
          me.success(data);
        },
        error: function (data) {
          me.error(data);
        }
      });
    },

    delStart: function () {
      var me = this;

      $.ajax({
        type: 'DELETE',
        url: this.url,
        contentType: this.dataType,
        async: this.async,
        data: this.data,
        beforeSend: function (data) {

        },
        success: function (data) {
          me.success(data);
        },
        error: function (data) {
          me.error(data);
        }
      });
    },

    putStart: function () {
      var me = this;

      $.ajax({
        type: 'PUT',
        url: this.url,
        contentType: this.dataType,
        async: this.async,
        data: this.data,
        beforeSend: function (data) {

        },
        success: function (data) {
          me.success(data);
        },
        error: function (data) {
          me.error(data);
        }
      });
    },

    getStart: function () {
      var me = this;

      $.ajax({
        type: 'GET',
        url: this.url,
        contentType: this.dataType,
        async: this.async,
        data: this.data,
        beforeSend: function (data) {

        },
        success: function (data) {
          me.success(data);
        },
        error: function (data) {
          me.error(data);
        }
      });
    },

    set: function (key, value) {
      if (typeof key == "object") {
        for (var i in key) {
          if (typeof i == "function") {
            continue;
          }
          this.data[i] = key[i];
        }
      } else {
        this.data[key] = (typeof value == "undefined") ? $("#" + key).val()
            : value;
      }
      return this;
    },

    setData: function (data) {
      this.data = data;
      return this;
    },

    clear: function () {
      this.data = {};
      return this;
    }
  };

  window.$ajax = $ajax;

}());